package com.qo.qsdk.ui;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.Nullable;

import com.qo.qsdk.QSDK;
import com.qo.qsdk.ui.base.FloatIconView;
import com.qo.qsdk.ui.base.FloatView;

public class FloatActivity extends BaseActivity {

    private FloatView mFloatView;
    public static final String TIP_EXTRA_TITLE = "TIP_EXTRA_TITLE";
    public static final String TIP_EXTRA_URL = "TIP_EXTRA_URL";

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mFloatView = new FloatView(this, mQSDKListener);
        mFloatView.show(this, getIntent().getStringExtra(TIP_EXTRA_TITLE), getIntent().getStringExtra(TIP_EXTRA_URL));
    }

    public static void show(Activity activity, String title, String url) {
        Intent intent = new Intent(activity, FloatActivity.class);
        intent.putExtra(TIP_EXTRA_TITLE, title);
        intent.putExtra(TIP_EXTRA_URL, url);
        activity.startActivity(intent);
    }

    @Override
    public void onBackPressed() {
        if (mQSDKListener != null) mQSDKListener.onFloatClose();
        super.onBackPressed();
    }

    QSDKListener mQSDKListener = new QSDKListener(){

        @Override
        public void onFloatClose() {
            finish();
        }

        @Override
        public void onFloatRefresh() {
            mFloatView.show(FloatActivity.this, getIntent().getStringExtra(TIP_EXTRA_TITLE), getIntent().getStringExtra(TIP_EXTRA_URL));
        }
    };

}
